<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <!-- MOTW-DISABLED saved from url=(0014)about:internet -->
    <title>Writing Expressions</title>
    <link rel="StyleSheet" href="css/expressions.css" type="text/css" media="all" />
    <link rel="StyleSheet" href="css/webworks.css" type="text/css" media="all" />
    <link rel="StyleSheet" href="webworks.css" type="text/css" media="all" />
    <script type="text/javascript" language="JavaScript1.2">
      <!--
        var  WebWorksRootPath = "";
      // -->
    </script>
  </head>
  <body>
    <div style="text-align: left;">
      <table cellspacing="0" summary="">
        <tr>
          <td>
            <a href="ag-HowToDisplayAggregateData.html"><img src="images/prev.gif" alt="Previous" border="0" /></a>
          </td>
          <td>
            <a href="fl-FilteringData.html"><img src="images/next.gif" alt="Next" border="0" /></a>
          </td>
        </tr>
      </table>
    </div>
    <hr align="left" />
    <blockquote>
      <h2 class="zTitleChapter"><a name="185998">Writing Expressions</a></h2>
      <p class="b_Body"><a name="186000">You can create many reports using data that comes directly from a data source simply by dragging the data set fields from Data Explorer to the report. Sometimes, however, you want to display information that is not in the data source, or you want to display data differently from the way it appears in the data source. You might also want to sort data using a formula, rather than sorting on an existing field. For these cases, and many others, write expressions using JavaScript.</a></p>
      <p class="b_Body"><a name="186009">An expression is a statement that produces a value. An expression can be a literal value, such as:</a></p>
      <div class="cf_CodeFirst"><a name="186010">3.14</a></div>
      <div class="co_Code"><a name="186011">"It is easy to create reports with BIRT"</a></div>
      <p class="b_Body"><a name="234116">When you drag a field into the report, BIRT Report Designer creates a column binding with the correct expression. The expression specifies the name of the field from which the report displays values. For example, the following expressions get values from the customerName field and the phone field, respectively:</a></p>
      <div class="cf_CodeFirst"><a name="186017">dataSetRow["customerName"]</a></div>
      <div class="co_Code"><a name="186018">dataSetRow["phone"]</a></div>
      <p class="b_Body"><a name="234381">An </a>expression can contain any combination of literal values, fields, operators, variables, and functions that evaluates to a single value. In the following examples, the first expression combines static text with a field, the second uses a JavaScript function, and the third multiplies the values of two fields:</p>
      <div class="cf_CodeFirst"><a name="186023">"Order Total: " + row["orderTotal"]</a></div>
      <div class="co_Code"><a name="186024">row["orderDate"].getYear()</a></div>
      <div class="co_Code"><a name="198892">row["itemQuantity"] * row["itemPrice"]</a></div>
      <p class="b_Body"><a name="230932">&nbsp;</a></p>
      <p class="b_Body"><a name="227689">&nbsp;</a></p>
    </blockquote>
    <hr align="left" />
    <table align="right" summary="">
      <tr>
        <td class="WebWorks_Company_Name_Bottom">
          <a href="notices.html">(c) Copyright Actuate Corporation 2013</a>
        </td>
      </tr>
    </table>
  </body>
</html>